import math

def getdelta(n, m):
	li = []
	for i in range(m-1):
		li.append(2)
	for i in range(n-m):
		li.append(1)
	return li

def iter(f, delta):
	f0 = f[0]
	if f0 % 2 == 0:
		a = f0 / 2
	else:
		a = ((f0 - 1) / 2) + 1

	del f[0]
	f.append(0)
	
	if f0 % 2 == 0:
#		print "c0"
		for i in range(len(f)):
			f[i] = f[i] - a * delta[i]
	else:
#		print "c1"
		for i in range(len(f)):
			f[i] = 2 * f[i] - f0 * delta[i]
	
	if f[0] < 0:
#		print "negate"
		for i in range(len(f)):
			f[i] *= -1
	
	return f

def run(n, m, max):
	delta = getdelta(n, m)

	orig = [0] * (n - 1)
	orig[0] = 1
	print orig

	f = list(orig)
	f = iter(f, delta)
	print f

	i = 0
	while f != orig and i < max:
		f = iter(f, delta)

		total = 0
		for j in range(len(f)):
			total += math.fabs(f[j])
		
		print f#, total
		
		i += 1

run(4, 3, 40)
